package com.hxl.demo.controller;

import com.hxl.demo.entity.TrainingRecord;
import com.hxl.demo.mapper.TrainingStatisticsMapper;
import com.hxl.demo.param.TrainingStatisticsParam;
import com.hxl.demo.service.TrainingStatisticsService;
import com.hxl.demo.tools.Common;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.*;

/**
 * 培训统计
 */
@RequestMapping("/admin")
@RestController
public class TrainingStatisticsController {
    @Autowired
    private TrainingStatisticsService trainingStatisticsService;

    @Resource
    private TrainingStatisticsMapper trainingStatisticsMapper;


    /**
     * 培训统计列表
     * @param param
     * @return
     */
    @RequestMapping("/getTraining")
    public Object getTraining( TrainingStatisticsParam param){
        List<Map<String,Object>> queryList1 = trainingStatisticsService.queryList(param);
        for(Map<String,Object> maps:queryList1){
            Integer count=0;
            if(maps.get("user_id")!=null){
                count=trainingStatisticsMapper.queryCountById(Integer.valueOf(maps.get("user_id").toString()));
                maps.put("cumulative_time",count);
            }

        }


        param.setQueryList(queryList1);
        Integer num= trainingStatisticsService.queryListNum(param);
        param.setTotal(num);

        return param;
    }


    /**
     * 培训详情
     * @return
     */
    @RequestMapping("/getTrainingDetails")
    public Object getTrainingDetails(TrainingStatisticsParam param){
        List<Map<String,Object>> queryDetails = trainingStatisticsService.queryDetails(param);
        Integer num =trainingStatisticsService.queryDetailsNum(param);
        param.setTotal(num);
        param.setQueryList(queryDetails);

        return param;
    }
}
